package br.com.dbsti.construtortelas;

import javax.swing.JLabel;
import javax.swing.JTextField;

public class EditorPais extends EditorObjetos<Pais> {

    private JTextField txtID;
    private JTextField txtNome;
    private JTextField txtSigla;
    private JTextField txtCodigoIBGE;
    
    @Override
    protected void preencherCamposTela() {
        this.txtID.setText(this.valor.getId() != null ? valor.getId().toString() : "");
        this.txtNome.setText(this.valor.getNome());
        this.txtSigla.setText(this.valor.getSigla());
        this.txtCodigoIBGE.setText(this.valor.getCodigoIBGE());
    }

    @Override
    protected void lerCamposTela() {
        this.valor.setId(
                this.txtID.getText().isEmpty() 
                    ? null 
                    : Long.valueOf(this.txtID.getText()));
        this.valor.setNome(this.txtNome.getText());
        this.valor.setSigla(this.txtSigla.getText());
        this.valor.setCodigoIBGE(this.txtCodigoIBGE.getText());
    }
    
    @Override
    public void adicionarEditorPropriedades() {
        this.add(new JLabel("ID:"), "cell 0 0");
        this.txtID = new JTextField();
        this.add(this.txtID, "cell 1 0, w 100px");
        
        this.add(new JLabel("Nome:"), "cell 0 1");
        this.txtNome = new JTextField();
        this.add(this.txtNome, "cell 1 1, w 250px");
        
        this.add(new JLabel("Sigla:"), "cell 0 2");
        this.txtSigla = new JTextField();
        this.add(this.txtSigla, "cell 1 2, w 50px");
        
        this.add(new JLabel("Código IBGE:"), "cell 0 3");
        this.txtCodigoIBGE = new JTextField();
        this.add(this.txtCodigoIBGE, "cell 1 3, w 100px");
    }
    
}
